package com.zmj.sy.mom.srv.aps.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmj.sy.mom.srv.aps.bean.entity.order.Order;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BasePageResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.test.FalsifyingDataReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.test.TestTableReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.test.TestTableResVo;
import com.zmj.sy.mom.srv.aps.service.ApsDayOrderService;
import com.zmj.sy.mom.srv.aps.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Api(tags = "测试接口")
@RestController
@RequestMapping("/test")
public class TestController {


    private final TestService testService;
    private final ApsDayOrderService apsDayOrderService;

    @SneakyThrows
    @ApiOperation("伪造开报工数据")
    @GetMapping("/falsifyingData")
    public BaseResVo falsifyingData(FalsifyingDataReqVo reqVo) {
        testService.falsifyingData(reqVo);
        return BaseResVo.ok();
    }

    @SneakyThrows
    @ApiOperation("测试套料策略")
    @GetMapping("/initSpan")
    public BaseResVo initSpan(String code) {

//        NestRule nestRule = strategyConfig.getNestRule(code);
//        nestRule.pushPart(null);
//        System.out.println(nestRule);


        return BaseResVo.ok();
    }

    /*@ApiOperation("修改外购件领料单号")
    @PostMapping("/fixWl")
    public BaseResVo fixWl(@RequestBody List<WmsPartProcurementReqDto> wmsReqDto, @RequestParam("orderId") Integer orderId) {
        testService.fixWl(orderId, wmsReqDto);
        return BaseResVo.ok();
    }*/

//    private final QmsOldApiClient qmsOldApiClient;
//    private final OrderMapper orderMapper;
//    private final PudaApiClient pudaApiClient;
//
//    @SneakyThrows
//    @ApiOperation("初始化跨别")
//    @GetMapping("/initSpan")
//    public BaseResVo initSpan() {
//        List<String> lines = FileUtils.readLines(new File("d:/temp/span.txt"));
//        testService.initSpan(lines);
//        return BaseResVo.ok();
//    }
//
//    @SneakyThrows
//    @ApiOperation("初始化跨别")
//    @GetMapping("/initGroup")
//    public BaseResVo initGroup() {
//        List<String> lines = FileUtils.readLines(new File("d:/temp/group.txt"));
//        testService.initGroup(lines);
//        return BaseResVo.ok();
//    }
//
//    @SneakyThrows
//    @ApiOperation("初始化工位")
//    @GetMapping("/initStation")
//    public BaseResVo initStation(){
//        List<String> lines = FileUtils.readLines(new File("d:/temp/station.txt"));
//        testService.initStation(lines);
//        return BaseResVo.ok();
//    }
//
//    @SneakyThrows
//    @ApiOperation("初始化料位")
//    @GetMapping("/initPosition")
//    public BaseResVo initPosition(){
//        List<String> upLines = FileUtils.readLines(new File("d:/temp/position.txt"));
//        testService.initPosition(upLines);
//        return BaseResVo.ok();
//    }
//    @GetMapping("/test")
//    public BaseResVo test(Integer id){
//        Order order = orderMapper.selectById(id);
//        qmsOldApiClient.bomSync(order);
//        return BaseResVo.ok();
//    }
//
//    @GetMapping("/aa")
//    public BaseResVo aa(){
//
//        String userCode = SySecurityUtils.getUserCode();
//        System.out.println(userCode);
//
////        String groupCode, String plateCode, BigDecimal thickness, String plateDxfUrl, String plmId, String quantity;
//
////        pudaApiClient.sendNestResult("1-3_JGQG_00", "15_030_AG_22_0978", new BigDecimal(30), "http://172.31.3.110:15261/Nestings/0/20.dxf", "KY498-0101-Z20_170", "1");
//        return BaseResVo.ok();
//    }
//
//    @GetMapping("/validCount")
//    public BaseResVo validCount(Integer orderId){
//        List<Order> orderList = testService.orderList();
//        for (Order order : orderList) {
//            testService.validCount(order.getId());
//        }
//        return BaseResVo.ok();
//    }

    @SneakyThrows
    @GetMapping("/phase")
    public BaseResVo phase(){

//        testService.phase();
//
//        testService.phaseJob();

//        testService.phaseFix();

//        testService.phaseType();
        return BaseResVo.ok();
    }

    @ApiOperation("测试修改")
    @PostMapping("/modifyTest")
    public void modifyTest(){
        testService.modifyTest();
    }

    @ApiOperation("交集判断")
    @PostMapping("/retainAll")
    public void retainAll(){
        List<String> a = new ArrayList<>();
        a.add("1");
        a.add("2");
        a.add("3");
        List<String> b = new ArrayList<>();
        b.add("2");
        b.add("4");
        b.add("5");
        List<String> c = new ArrayList<>();
        c.add("6");
        c.add("7");
        c.add("8");
        List<String> d = new ArrayList<>();
        d.add("1");
        d.add("2");
        d.add("3");
        // 有交集返回 false，没有交集返回 true
        System.out.println(Collections.disjoint(a, b));
        System.out.println(Collections.disjoint(a, c));
        // 布尔值指前一列表内容是否发生了变化，前一列表取两列表的交集，修改前一列表内容
        boolean b1 = a.retainAll(b);
        System.out.println(b1);
        System.out.println(a);
        // boolean b2 = d.retainAll(c);
        // System.out.println(b2);
        // System.out.println(d);
        // boolean b3 = a.retainAll(d);
        // System.out.println(b3);
        // System.out.println(a);
    }

    @ApiOperation("测试通知立体库删除外购件领料单功能")
    @PostMapping("/deletePickIng")
    public BaseResVo deletePickIng(@RequestBody BaseIdReqVo reqVo) {
        return testService.deletePickIng(reqVo);
    }

    @ApiOperation("以orderId解锁删除套料信息")
    @PostMapping("/unlockDeleteNest")
    public BaseResVo unlockDeleteNest(@RequestBody BaseIdReqVo reqVo) throws Exception {
        testService.unlockDeleteNest(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("PT报工")
    @PostMapping("/ptReport")
    public BaseResVo ptReport() {
        testService.ptReport();
        return BaseResVo.ok();
    }

    @ApiOperation("测试数量扣减")
    @PostMapping("/testCount")
    public BaseResVo testCount() {
        testService.testCount();
        return BaseResVo.ok();
    }

    @ApiOperation("兰特克测试——删除套料相关结果")
    @PostMapping("/deleteLanNest")
    public BaseResVo deleteLanNest(@RequestBody String nestCode) {
        testService.deleteLanNest(nestCode);
        return BaseResVo.ok();
    }

    @ApiOperation("测试异常信息发送到飞书")
    @PostMapping("/sendMsgFlyBook")
    public BaseResVo sendMsgFlyBook(@RequestParam("userCode") String userCode,@RequestParam("title") String title,@RequestParam("msg") String msg) {
        testService.sendMsgFlyBook(userCode, title, msg);
        return BaseResVo.ok();
    }

    @ApiOperation("表格测试")
    @PostMapping("/table")
    public BasePageResVo<TestTableResVo> table(@RequestBody TestTableReqVo reqVo) {

        // 自动处理相关的工作组
        apsDayOrderService.autoCheck(LocalDate.of(2025,10,14));
        Page<Order> table = testService.table(reqVo);

        return BasePageResVo.of(table, TestTableResVo.class);
//        return BaseResVo.ok();
    }

}
